﻿using Commonality.Model.Xml;
using Merge.BLL.Cave;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Merge.BLL.CaverForm
{
    public partial class CaverConfigForm : Form
    {
        public CaverConfigForm()
        {
            InitializeComponent();
        }

        private void CaverConfigForm_Load(object sender, EventArgs e)
        {
            CaverConfig.CaverConfigInit();
            CaverConfigFormInit();
        }
        private void CaverConfigFormInit()
        {
            CaverOldTimeComBox.Text = CaverConfig.OldTime.ToString();
            OldTimeComboBox.Text = CaverConfig.OldTimeStaNum.ToString();
        }
        private void CaverOldTimeComBox_TextChanged(object sender, EventArgs e)
        {
            CaverConfig.UpOldTIme(CaverOldTimeComBox.Text);
        }

        private void OldTimeComboBox_TextChanged(object sender, EventArgs e)
        {
            CaverConfig.UpOldNum(OldTimeComboBox.Text);
        }

        private void OpenAimFormButton_Click(object sender, EventArgs e)
        {
            SeekForm seekForm = new SeekForm();
            seekForm.ShowDialog();
        }
    }

    public static class CaverConfig
    {
        public static string parameterFeilName = Application.StartupPath + @"\Parameter\CaverConfig.xml";

        #region 参数字段
        /// <summary>
        /// 超时时间
        /// </summary>
        public static double OldTime;
        /// <summary>
        /// 激活超时器最小空窗数
        /// </summary>
        public static int OldTimeStaNum;
        #endregion
        public static void CaverConfigInit()
        {
            CaverConfigDataLoad();
        }
        public static void CaverConfigDataLoad()
        {
            try
            {
                OldTime = Convert.ToDouble(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "OldTime", "Time"));
                OldTimeStaNum = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "OldTime", "Num"));

                CaveModel.AwaitTimeProgramme = OldTime * 3600;
                Caver.LeastLeisureNum = OldTimeStaNum;
            }
            catch (Exception)
            {
            }

        }

        public static void UpOldTIme(string time)
        {
            try
            {
                XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "OldTime", "Time", time);
                CaveModel.AwaitTimeProgramme = Convert.ToDouble(time) * 3600;
            }
            catch (Exception)
            {
            }

        }
        public static void UpOldNum(string num)
        {
            try
            {
                XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "OldTime", "Num", num);
                Caver.LeastLeisureNum = Convert.ToInt16(num);
            }
            catch (Exception)
            {
            }
        }
    }

}
